#include <glib.h>

GPrivate private = G_PRIVATE_INIT (g_free);

static gpointer _thread_1_func(gpointer data)
{
    gpointer *pri_val = NULL;
    pri_val = g_private_get(&private);
    g_print("pri_val(ori): %s \n", (gchar *)pri_val);

    g_private_set(&private, g_strdup("abcd"));
    pri_val = g_private_get(&private);
    g_print("pri_val(set): %s \n", (gchar *)pri_val);
}

static gpointer _thread_2_func(gpointer data)
{
    gpointer *pri_val = NULL;
    pri_val = g_private_get(&private);
    g_print("pri_val(ori): %s \n", (gchar *)pri_val);

    g_private_set(&private, g_strdup("123456"));
    pri_val = g_private_get(&private);
    g_print("pri_val(set): %s \n", (gchar *)pri_val);

    g_private_replace(&private, g_strdup("AABBC"));
    pri_val = g_private_get(&private);
    g_print("pri_val(replace): %s \n", (gchar *)pri_val);
}

void test_thread_private(void)
{
    GThread *th1,*th2;

    g_print("\n");

    th1 = g_thread_new("th1", _thread_1_func, NULL);
    th2 = g_thread_new("th2", _thread_2_func, NULL);
    g_thread_join(th1);
    g_thread_join(th2);
}

gint main(gint argc, gchar **argv)
{
    g_test_init(&argc, &argv, NULL);

    g_test_add_func("/thread/private", test_thread_private);

    return g_test_run();
}